import aiomysql
from app.core.config import settings

# 定义全局连接池变量
db_pool = None

async def init_db_pool():
    global db_pool
    db_pool = await aiomysql.create_pool(
        host=settings.DB_HOST,
        port=settings.DB_PORT,
        user=settings.DB_USER,
        password=settings.DB_PASSWORD,
        db=settings.DB_NAME,
        cursorclass=aiomysql.cursors.DictCursor,
        maxsize=10 if settings.DEBUG else 20
    )

async def close_db_pool():
    global db_pool
    if db_pool:
        db_pool.close()
        await db_pool.wait_closed()